package org.mclll.xwangplugin.mcmmoCustom.poiont.command;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mclll.xwangplugin.MclllCustom;
import org.mclll.xwangplugin.mcmmoCustom.poiont.config.ProbBrewerConfig;

import java.util.Collections;
import java.util.List;

import static org.mclll.xwangplugin.town.config.TownContext.NOT_PERMISSION;

public class PointReload implements TabExecutor {

    private MclllCustom plugin;

    public PointReload(MclllCustom mclllCustom) {
        plugin = mclllCustom;
    }

    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
        if (!sender.isOp()) {
            sender.sendMessage(NOT_PERMISSION);
        }
        if (args.length == 1 && "reload".equals(args[0])) {
            ProbBrewerConfig.load(plugin.getDataFolder(), plugin.getPointListener().getPotionConfig());
            sender.sendMessage("载入成功");
            return true;
        }
        return false;
    }

    @Override
    public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
        return Collections.singletonList("reload");
    }
}
